package cn.tedu.charging.cost.config;

import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.serializer.RedisSerializer;

/**
 * Redis配置类
 */
@Slf4j
@Configuration
public class RedisConfiguration {

    /**
     * @Bean RedisTemplate类型的bean对象 创建并返回
     * @param factory
     * @return
     */
    @Bean
    public RedisTemplate configureRedisTemplate(RedisConnectionFactory  factory) {
        log.debug("创建配置类对象：RedisConfiguration");
        RedisTemplate redisTemplate = new RedisTemplate();
        redisTemplate.setConnectionFactory(factory);
        //设置Redis key 的序列化器 为  String
        redisTemplate.setKeySerializer(RedisSerializer.string());
        //设置Redis value 的序列化器 为  Json
        redisTemplate.setValueSerializer(RedisSerializer.json());
        return redisTemplate;
    }

}
